﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hrExaminationStandard.aspx.cs" Inherits="ZX.WebApp.EHR.hrExaminationStandard" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>考核标准</title>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script src="../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/Jquery.form.js" type="text/javascript"></script>
    <link href="../Styles/extendTable.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript">
    // <![CDATA[
            var fun = "";
            $(document).ready(function () {
                var solutionID = getPar1("solutionID");
                var solutionName = getPar1("solutionName");
                fun = getPar1("fun");
                $("#SolutionID1").val(solutionID);
                $("#SolutionName").html(solutionName);
                if (fun == "view") {
                    $("div input").attr("disabled", true).css("background", "whitesmoke");
                    $("div textarea").css("background", "whitesmoke");
                    $("div select").attr("disabled", true).css("background", "whitesmoke");
                    $("div input[type=button]").hide();
                }
                else {
                    parent.document.getElementById("dialog1_h").innerHTML = solutionName + "_考核标准";
                }
                GetStandard(solutionID);
            });

            //取得已存在的数据
            function GetStandard(solutionID) {
                var url = "../Extend/AjaxData/jsonlist.aspx?entity=ExaminationStandard&condition=SolutionID='" + solutionID + "'";
                $.get(url, function (d, s) {
                    var list = eval("(" + d + ")");
                    var i = 0;
                    if (list.rows.length > 0) {
                        for (var o in list.rows) {
                            //debugger;
                            var t = list.rows[o].ID;
                            if (typeof (t) != "undefined") {
                                CreateStandardSelect(list.rows[o]);
                            }
                        }
                    }
                    else {
                        CreateStandardSelect(null);
                    }
                });

            }

            //取得考核标准下拉框
            function CreateStandardSelect(obj) {
                YAHOO.util.Connect.asyncRequest('POST', "hrExaminationAjax.aspx?flag=createstandardselect", {
                    success: function (res) {
                        try {
                            //debugger;
                            var str = res.responseText;
                            $("#Cateory").empty();
                            $("#Cateory").append("<option value='' selected>请选择</option>");
                            $("#Cateory").append(str);
                            //加载行
                            addtr();
                            //debugger;
                            //修改查看时加载数据
                            var CateoryLength = document.getElementsByName("Cateory").length;  //获取Cateory对象个数
                            //alert(CateoryLength);
                            if (obj != null) {
                                //获取最后一行对像，即刚新增的行对像
                                var lastTr = $("#tbEmp tr").last();
                                //设置下拉框值
                                jsSelectItemByValue(document.getElementsByName("Cateory")[CateoryLength - 1], obj.CateoryID);
                                $("#SolutionID", lastTr).val(obj.SolutionID);
                                $("#CateoryID", lastTr).val(obj.CateoryID);
                                $("#Socre", lastTr).val(obj.Socre);
                                $("#FinishRate", lastTr).val(obj.FinishRate);
                            }
                        }
                        catch (e) {
                        }
                        finally {
                        }
                    },
                    failure: function (error) {
                        alert("数据错误：" + error.statusText);
                    }
                }, null);
            }

            ///设置select中Value="paraValue"的第一个Item为选中  
            function jsSelectItemByValue(objSelect, objItemValue) {
                //debugger;
                //判断是否存在        
                for (var i = 0; i < objSelect.options.length; i++) {
                    var arrstandard = objSelect.options[i].value.split("|");
                    if (arrstandard[0] == objItemValue) {
                        objSelect.options[i].selected = true;
                        break;
                    }
                }
            }

            //选择分类事件，带出默认值
            function SetStandardInfo(obj) {
                var tr = getTableRow(obj);
                var standard = $("#Cateory", tr).val();
                //alert(standard);
                if (standard != "") {
                    var arrstandard = standard.split("|");
                    $("#SolutionID", tr).val($("#SolutionID1").val());
                    $("#CateoryID", tr).val(arrstandard[0]);
                    $("#Socre", tr).val(arrstandard[2]);
                    $("#FinishRate", tr).val(arrstandard[3]);
                }
                else {
                    $("#CateoryID", tr).val("00000000-0000-0000-0000-000000000000");
                    $("#Socre", tr).val(0);
                    $("#FinishRate", tr).val(0);
                }
            }

            //增加行
            function addtr() {
                var tr = $("#tbEmp tr").eq(1).clone();
                tr.show();
                tr.appendTo("#tbEmp").removeClass("selectedTr").find(":checkbox").attr("checked", false);
            }

            //删除行
            function deltr() {
                //遍历tr
                $("#tbEmp tr").first().nextAll().each(function () {
                    if ($(this).hasClass("selectedTr")) {
                        $(this).remove();
                    }
                });
            };

            //选中行
            $("#tbEmp tr").live("click", function () {
                if ($(this).hasClass("selectedTr")) {
                    $(this).removeClass("selectedTr").find(":checkbox").attr("checked", false);
                } else {
                    $(this).addClass("selectedTr").find(":checkbox").attr("checked", true);
                }
            });

            //数据保存
            function Save() {
                //debugger;
                var solutionID = $("#SolutionID1").val();
                //存储行中的数据
                var _TempArray = [];

                if (solutionID == "") {
                    alert("方案为空！");
                    return;
                }               

                //遍历所有已选择员工
                $("#tbEmp tr").eq(1).nextAll().each(function () {
                    var id = $("#CateoryID", this).val();
                    if (id != "") {
                        _TempArray.push($(this).extractObject());
                    }
                });

                if (_TempArray.length == 0) {
                    alert("请至少选择一分类！");
                    return;
                }

                //将行转成JSON
                var json = $.toJSON(_TempArray);
                var Url = "hrExaminationAjax.aspx?flag=savestandard&json=" + encodeURI(json);

                //提交数据
                YAHOO.util.Connect.asyncRequest('POST', Url, {
                    success: function (res) {
                        try {
                            var str = res.responseText;
                            if (str.substring(0, 1) == "1") {
                                alert("数据保存成功!");
                                parent.closeWin();
                            }
                            else {
                                alert("数据保存失败,请检查");
                            }
                        }
                        catch (e) {
                        }
                        finally {
                        }
                    },
                    failure: function (error) {
                        alert("数据错误：" + error.statusText);
                    }
                }, null);
            }
    // ]]> 
     </script>
    <style type="text/css">
        body{font-family: 宋体, Arial, Helvetica, sans-serif;font-size: 12px;color: #333333;background-color: #FFFFFF;} 
        select{width:99%;} td { border: 1px solid #CCCCCC;}
        .textarea{ width: 96%;height: 25px;}	
        .selectedTr{  background-color: blue;} 
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table align="center" class="TableBlock" width="99%" id="tbMain" name="tbMain" style="display:none">
		    <tr>
			    <td align="left" class="TableData" width="200">考核方案：</td>
			    <td align="left" class="TableContent">
                    <span id="SolutionName"></span>
                    <input class="td_value3"  id="SolutionID1" name="SolutionID1"  style="width: 120px" type="hidden" />
                </td>
		    </tr>
    </table>
    <div id="divBtn">
        <input type="button" id="btnADD" value="新增" onclick="addtr();" />
        <input type="button" id="btnDEL" value="删除" onclick="deltr();" />
    </div>
    <table align="center" border="1" id="tbEmp" name="tbEmp" style="border-collapse: collapse" width="99%">
        <tr id="data_head" style="background-color: #e4e7e2">
           <td style="text-align: center"></td>
	        <td style="text-align: center">分类</td>
	        <td style="text-align: center">得分</td>
	        <td style="text-align: center">完成程度(%)</td>
        </tr>
        <tr style="display:none">
            <td>
                <input type="checkbox" id="chktr" name="chktr" convert="unconvert" />
            </td>
	        <td>
		        <select id="Cateory" name="Cateory" onchange="SetStandardInfo(this);" convert="unconvert" ></select>
		        <input  id="SolutionID" name="SolutionID"  type="hidden" value="00000000-0000-0000-0000-000000000000"/>
		        <input  id="CateoryID" name="CateoryID"  type="hidden" value="00000000-0000-0000-0000-000000000000"/>
            </td>
	        <td>
		        <input  id="Socre" name="Socre"  type="text" value="0"/>
            </td>
	        <td>
		        <input  id="FinishRate" name="FinishRate"  type="text" value="0" />
            </td>
        </tr>
    </table>
    </div>
    </form>
</body>
</html>
